package com.wing.purchase.service;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wing.common.enums.ProductEnum;
import com.wing.purchase.dao.BarterGoodsTypeDao;
import com.wing.purchase.model.entity.BarterGoodsType;
import com.wing.purchase.model.entity.ReturnGoodsType;
import com.wing.web.utils.JwtUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * 采购类型表-ServiceImpl
 *
 * @author
 */
@Service
@Slf4j
public class BarterGoodsTypeServiceImpl extends ServiceImpl<BarterGoodsTypeDao, BarterGoodsType> implements BarterGoodsTypeService {

    @Override
    public boolean disableOrEnable(Long id, String status) {
        BarterGoodsType byId = this.getById(id);
        if (ObjectUtil.isEmpty(byId)){
            return false;
        }
        if (status.equals(ProductEnum.templateStatusEmum.HF.getCode().equals(status))){
            byId.setIsDeleted(false);
        }else {
            byId.setIsDeleted(true);
        }
        byId.setUpdateTime(LocalDateTime.now());
        byId.setModifier(JwtUtils.getLoginUserId());
        byId.setModifierName(JwtUtils.getLoginUsername());
        return updateById(byId);
    }
}
